home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1158.ASC < prev    next >
Encoding:
Text File  |  1992-11-11  |  14.8 KB  |  595 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  November 11, 1992                        PAGE  :  1/9
  12.  
  13.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  14.  
  15.  
  16.  
  17.  
  18.  
  19.        The following code provides an example of executing a Modal
  20.   Dialog Box from another Dialog Box when using Turbo Vision.
  21.  
  22.  
  23.   /*********************************************************************\
  24.    * TEST.CPP                                                          *
  25.    *   This module contains the Turbo Vision application code to run   *
  26.    *   this example.  It sets up the necessary menus to bring up the   *
  27.    *   test module represented by this demo.                           *
  28.    *                                                                   *
  29.    * TEST MODULE for Dialog Example #3 : Creating a second modal dialog*
  30.    *   box from within a first.                                        *
  31.    *                                                                   *
  32.    *********************************************************************
  33.    *                                                                   *
  34.    * This code was written by Borland Technical Support.               *
  35.    * It is provided as is with no warranties expressed or implied.     *
  36.    *                                                                   *
  37.   \*********************************************************************/
  38.  
  39.   #define Uses_TRect
  40.   #define Uses_TKeys
  41.   #define Uses_TEvent
  42.   #define Uses_TDialog
  43.   #define Uses_TMenu
  44.   #define Uses_TMenuItem
  45.   #define Uses_TMenuBar
  46.   #define Uses_TDeskTop
  47.   #define Uses_TApplication
  48.   #include <tv.h>
  49.   #include <mem.h>
  50.  
  51.   #pragma hdrstop
  52.  
  53.   #include "cmds.h"
  54.   #include "mdlg.h"
  55.  
  56.  
  57.   class TTestApp : public TApplication
  58.   {
  59.  
  60.   public:
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  75.   VERSION  :  3.1
  76.        OS  :  DOS
  77.      DATE  :  November 11, 1992                        PAGE  :  2/9
  78.  
  79.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  80.  
  81.  
  82.  
  83.  
  84.       TTestApp() : TApplication(),
  85.                    TProgInit( initStatusLine, initMenuBar, initDeskTop )
  86.   { }
  87.       static TMenuBar *initMenuBar( TRect r );
  88.       virtual void handleEvent( TEvent& event );
  89.  
  90.   };
  91.  
  92.  
  93.   TMenuBar *TTestApp::initMenuBar( TRect r )
  94.   {
  95.       r.b.y = r.a.y + 1;
  96.       return new TMenuBar( r, new TMenu(
  97.           *new TMenuItem( "~D~ialog Box", cmEDialog, kbAltE )
  98.           ));
  99.   }
  100.  
  101.  
  102.   void TTestApp::handleEvent( TEvent& event )
  103.   {
  104.       TFirstDialog *td;
  105.  
  106.       TApplication::handleEvent( event );
  107.  
  108.       if( event.what == evCommand &&
  109.           event.message.command == cmEDialog )
  110.       {
  111.           td = new TFirstDialog( TRect(0,0,40,11),
  112.                                  "The first dialog box." );
  113.           if( validView( td ) )
  114.               deskTop->execView( td );
  115.       }
  116.   }
  117.  
  118.  
  119.   int main()
  120.   {
  121.       TTestApp TB;
  122.       TB.run();
  123.       return 0;
  124.   }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  141.   VERSION  :  3.1
  142.        OS  :  DOS
  143.      DATE  :  November 11, 1992                        PAGE  :  3/9
  144.  
  145.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  146.  
  147.  
  148.  
  149.  
  150.   /*********************************************************************
  151.    *                                                                   *
  152.    * MDLG.CPP                                                          *
  153.    *   This module contains the code for the two subclassed dialogs use*
  154.    *   by this demo.                                                   *
  155.    *                                                                   *
  156.    * SUPPORT MODULE for dialog example #3 : Creating a second modal    *
  157.    *   dialog box from within a first.                                 *
  158.    *                                                                   *
  159.    *   The key to this operation is making sure that the deskTop's     *
  160.    *   execView() function is used in all cases when a modal dialog box*
  161.    *   is desired.  execView() is a member function of TGroup, thus any*
  162.    *   class derived from TGroup will have its own version of that     *
  163.    *   function.  When inside a dialog box handleEvent procedure, code *
  164.    *   such as                                                         *
  165.    *                                                                   *
  166.    *      TDialog *td = ...                                            *
  167.    *      execView( td );                                              *
  168.    *                                                                   *
  169.    *   will compile, but the box will come up with lots of flashing    *
  170.    *   white on red colors.  This is because the new dialog box was    *
  171.    *   inserted into the old dialog box, instead of the deskTop and the*
  172.    *   palette isn't mapped right.  The solution is to execView the    *
  173.    *   dialog box this way:                                            *
  174.    *                                                                   *
  175.    *      TDialog *td = ...                                            *
  176.    *      TProgram::deskTop->execView( td );                           *
  177.    *                                                                   *
  178.    *  'deskTop' is a static public member of TProgram and points to the*
  179.    *   desktop object of the current application.  This way, the dialog*
  180.    *   box will be inserted into the desktop and the palettes will work*
  181.    *   properly.  The Z order will also be correct so that the views   *
  182.    *   stack up right.                                                 *
  183.    *                                                                   *
  184.    *********************************************************************
  185.    *                                                                   *
  186.    * This code was written by Borland Technical Support.               *
  187.    * It is provided as is with no warranties expressed or implied.     *
  188.    *                                                                   *
  189.    *********************************************************************/
  190.  
  191.   #define Uses_TRect
  192.   #define Uses_TKeys
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  207.   VERSION  :  3.1
  208.        OS  :  DOS
  209.      DATE  :  November 11, 1992                        PAGE  :  4/9
  210.  
  211.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  212.  
  213.  
  214.  
  215.  
  216.   #define Uses_TEvent
  217.   #define Uses_TButton
  218.   #define Uses_TStaticText
  219.   #define Uses_TDialog
  220.   #define Uses_MsgBox
  221.   #define Uses_TDeskTop
  222.   #define Uses_TProgram
  223.   #include <tv.h>
  224.  
  225.   #pragma hdrstop
  226.  
  227.   #include "cmds.h"
  228.   #include "mdlg.h"
  229.  
  230.  
  231.   /********************************************************************
  232.    *   Class TFirstDialog                                             *
  233.    ********************************************************************
  234.    * TFirstDialog::TFirstDialog                                       *
  235.    *   Constructor for the dialog box.  Encapsulates the box to ease  *
  236.    *   creation.                                                      *
  237.    ********************************************************************/
  238.  
  239.   TFirstDialog::TFirstDialog( TRect& r, char *aTitle ) :
  240.       TDialog( r, aTitle ),
  241.       TWindowInit( initFrame )
  242.   {
  243.       insert( new TStaticText( TRect(2,2,38,6),
  244.          "This is a modal dialog box.  Hitting the <More> button below "
  245.          "will bring up a second modal dialog box on top of this one."
  246.           ));
  247.  
  248.       insert( new TButton( TRect(2,8,12,10),
  249.                           "~M~ore", cmMore, bfDefault )
  250.             );
  251.       insert( new TButton( TRect(14,8,24,10), "O~K~", cmOK, bfNormal )
  252.             );
  253.       insert( new TButton( TRect(26,8,36,10), "~C~ancel", cmCancel,
  254.                            bfNormal )
  255.             );
  256.  
  257.       selectNext( False );
  258.       options |= ofCentered;
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  273.   VERSION  :  3.1
  274.        OS  :  DOS
  275.      DATE  :  November 11, 1992                        PAGE  :  5/9
  276.  
  277.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  278.  
  279.  
  280.  
  281.  
  282.   }
  283.  
  284.  
  285.   /***********************************************************************
  286.    * TFirstDialog::handleEvent
  287.    *   Handle the <More> button and bring up the second dialog box when
  288.    *   this button is pushed.
  289.    ***********************************************************************/
  290.  
  291.   void TFirstDialog::handleEvent( TEvent& event )
  292.   {
  293.       TSecondDialog *td;
  294.  
  295.       if( event.what == evCommand )
  296.           switch( event.message.command )
  297.           {
  298.           case cmMore:               // Brings up a second dialog box...
  299.               td = new TSecondDialog( TRect(0,0,38,9),
  300.                                       "The second dialog box."
  301.                                     );
  302.               if( TProgram::application->validView( td ) )
  303.                   TProgram::deskTop->execView( td );
  304.               clearEvent( event );
  305.               break;
  306.           }
  307.  
  308.       TDialog::handleEvent( event );
  309.   }
  310.  
  311.  
  312.   /**********************************************************************
  313.    *
  314.    * Class TSecondDialog
  315.    *
  316.    **********************************************************************
  317.    * TSecondDialog::TSecondDialog
  318.    *   A fairly cheezy second dialog box with an ok button to make it go
  319.    *   away.  (This is probably a good thing :-) )
  320.    ***********************************************************************/
  321.  
  322.   TSecondDialog::TSecondDialog( TRect& r, char *aTitle ) :
  323.       TDialog( r, aTitle ),
  324.       TWindowInit( initFrame )
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  339.   VERSION  :  3.1
  340.        OS  :  DOS
  341.      DATE  :  November 11, 1992                        PAGE  :  6/9
  342.  
  343.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  344.  
  345.  
  346.  
  347.  
  348.   {
  349.       insert( new TStaticText( TRect(2,2,36,5),
  350.         "This the second modal dialog box.  Hitting the <OK> button or "
  351.         "<Esc> will make it go away."
  352.           ));
  353.  
  354.       insert( new TButton( TRect(13,6,23,8), "O~K~", cmOK, bfDefault )
  355.             );
  356.       options |= ofCentered;
  357.   }
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.   /*********************************************************************
  370.    *                                                                   *
  371.    * CMDS.H                                                            *
  372.    *   This header contains various commands used in the main message  *
  373.    *   system (including the menu bar, status line, and miscellaneous  *
  374.    *   dialog boxes.)                                                  *
  375.    *                                                                   *
  376.    *********************************************************************
  377.    *                                                                   *
  378.    * This code was written by Borland Technical Support.               *
  379.    * It is provided as is with no warranties expressed or implied.     *
  380.    *                                                                   *
  381.    *********************************************************************/
  382.  
  383.   #ifndef _CMDS_H
  384.   #define _CMDS_H
  385.  
  386.   const unsigned short cmEDialog      = 100;
  387.   const unsigned short cmMore         = 101;
  388.  
  389.   #endif
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  405.   VERSION  :  3.1
  406.        OS  :  DOS
  407.      DATE  :  November 11, 1992                        PAGE  :  7/9
  408.  
  409.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  410.  
  411.  
  412.  
  413.  
  414.   /*********************************************************************
  415.    *                                                                   *
  416.    * MDLG.H                                                            *
  417.    *   This header contains the class definitions for the MDLG.CPP     *
  418.    *   source module.                                                  *
  419.    *                                                                   *
  420.    * CLASSES                                                           *
  421.    *   TFirstDialog           The first dialog box.                    *
  422.    *   TSecondDialog          The second dialog box.                   *
  423.    *                                                                   *
  424.    *********************************************************************
  425.    *                                                                   *
  426.    * This code was written by Borland Technical Support.               *
  427.    * It is provided as is with no warranties expressed or implied.     *
  428.    *                                                                   *
  429.    *********************************************************************/
  430.  
  431.  
  432.   class TFirstDialog : public TDialog
  433.   {
  434.  
  435.   public:
  436.  
  437.       TFirstDialog( TRect& r, char *aTitle );
  438.       virtual void handleEvent( TEvent& event );
  439.  
  440.   };
  441.  
  442.  
  443.   class TSecondDialog : public TDialog
  444.   {
  445.  
  446.   public:
  447.  
  448.       TSecondDialog( TRect& r, char *aTitle );
  449.  
  450.   };
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  471.   VERSION  :  3.1
  472.        OS  :  DOS
  473.      DATE  :  November 11, 1992                        PAGE  :  8/9
  474.  
  475.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  476.  
  477.  
  478.  
  479.  
  480.   #
  481.   # Makefile for Turbo Vision sample demo
  482.   #
  483.   # Written by Borland Tech Support, 1992.
  484.   #
  485.   .AUTODEPEND
  486.  
  487.   NAME    = test
  488.   OBJS    = $(NAME).obj mdlg.obj
  489.  
  490.   DEBUG   = -v
  491.   MODEL   = -ml
  492.   MAP     = -x
  493.   INCPATH = C:\BORLANDC\INCLUDE;C:\BORLANDC\TVISION\INCLUDE
  494.   LIBPATH = C:\BORLANDC\LIB;C:\BORLANDC\TVISION\LIB
  495.  
  496.   CFLAGS  = -c -H=$(NAME).sym $(DEBUG) $(MODEL)
  497.   LFLAGS  = $(MAP) $(DEBUG) -Vt -L$(LIBPATH)
  498.   CC      = bcc
  499.   LINK    = tlink
  500.  
  501.   .cpp.obj:
  502.       $(CC) +$(NAME).cfg {$*.cpp }
  503.  
  504.   .c.obj:
  505.       $(CC) +$(NAME).cfg {$*.c }
  506.  
  507.   $(NAME).exe: $(NAME).cfg $(OBJS)
  508.       $(LINK) @&&~
  509.   $(LFLAGS) c0l +
  510.   $(OBJS)
  511.   $(NAME).exe
  512.   $(NAME).map
  513.   tv +
  514.   emu + mathl + cl
  515.   ~
  516.  
  517.   $(NAME).cfg: makefile
  518.           copy &&~
  519.   $(CFLAGS) -I$(INCPATH) -L$(LIBPATH)
  520.   ~ $(NAME).cfg
  521.  
  522.   clean:
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.   PRODUCT  :  Borland C++                           NUMBER  :  1158
  537.   VERSION  :  3.1
  538.        OS  :  DOS
  539.      DATE  :  November 11, 1992                        PAGE  :  9/9
  540.  
  541.     TITLE  :  A modal dialog from a modal dialog with Turbo Vision
  542.  
  543.  
  544.  
  545.  
  546.       del *.sym *.obj *.exe *.cfg
  547.  
  548.  
  549.  
  550.  
  551.  
  552.   DISCLAIMER: You have the right to use this technical information
  553.   subject to the terms of the No-Nonsense License Statement that you
  554.   received with the Borland product to which this information pertains.
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.